import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import nl.ansuz.android.steam.dota.request.DotaRequest;
import nl.ansuz.android.steam.dota.request.match.GetMatchDetails;
import nl.ansuz.android.steam.dota.request.match.GetMatchHistory;
import nl.ansuz.android.steam.dota.response.match.GetMatchHistoryResponse;
import nl.ansuz.android.steam.request.SteamRequest;
import nl.ansuz.android.steam.util.GsonUtil;

import com.google.gson.Gson;


public class GetMatchHistoryLoopTest {
	public static void main(String[] args) throws IOException {

		long matchid =-1;
		long datemax =-1;
		
		while (true)
		{
			GetMatchHistory getMatchHistory = new GetMatchHistory();
			Map<String, String> params = new HashMap<String, String>();

			params.put(SteamRequest.Parameter.API_KEY, "18755ABB58C0BE96815AE471FBB1C3F2");
			if (matchid!=-1)
				params.put("start_at_match_id", ""+matchid);
			// params.put("account_id","111931499");
			if (datemax!=-1)
				params.put("date_max",""+datemax);

			//  params.put("date_max","1378771200");
			// params.put("start_at_match_id", "508");
			//params.put("skill", "1");
			String url = getMatchHistory.createRequestUrl(DotaRequest.ApplicationID.LIVE, params);

			System.out.println(url);

			String resopnse = ManipulaHttp2.executaConsulta(url);
			//System.out.println(resopnse);

			GsonUtil gsonUtil = new GsonUtil();

			Gson gson = new Gson();

			GetMatchHistoryResponse getMatchHistoryResponse = gson.fromJson(gsonUtil.getStrippedDotaResult(resopnse), GetMatchHistoryResponse.class);

			System.out.println("---");
			for (int i=0;i<getMatchHistoryResponse.matches.length;i++)
			{
				System.out.println(getMatchHistoryResponse.matches[i].matchId+":"+ getMatchHistoryResponse.matches[i].startTime);
			}
			if (getMatchHistoryResponse.matches.length>0)
			{
			datemax = getMatchHistoryResponse.matches[getMatchHistoryResponse.matches.length-1].startTime;
			matchid = getMatchHistoryResponse.matches[getMatchHistoryResponse.matches.length-1].matchId;
			}
			else
				System.out.println("?");

		}

	}
}
